import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
  const user = ref<User>({
    token: '',
    userName: '',
    name: '',
    id: '',
  })
  const setToken = (val: string) => {
    user.value.token = val;
  }
  const removeToken = () => {
    user.value.token = ''
  }
  const initUserInfo = ({ id, name, userName, token }: User) => {
    user.value.id = id
    user.value.name = name
    user.value.userName = userName
    user.value.token = token
  }
  const destroyUserInfo = () => {
    user.value.id = ''
    user.value.name = ''
    user.value.userName = ''
    user.value.token = ''
  }

  return { user, setToken, removeToken, initUserInfo, destroyUserInfo }
}, {
  persist: true
})
